import Common from '../../common/common.js';
import TimNet from "../../timnet.js";

function MessListPointItem(info,type) {
    this.element;
    this.info = info;
    this.type = type;
    this.initElement();
}

MessListPointItem.prototype = {
    initElement:function(){
        this.element = Common.tool.createElement({label:"li",props:{className:this.type,innerText:this.info}});
    },
    appendUserName:function(userId){
        if(Common.cache.userInfo[userId]){
            const user = Common.cache.userInfo[userId];
            this.element.innerText =  "\""+(Common.tool.isNull(user.nick)?user.userID:user.nick)+"\"" + this.info;

        }else{
            TimNet.getUserProfile([userId],(userlist)=>{
                if(userlist.length > 0){
                    Common.cache.userInfo[userId] = userlist[0];
                    const user = Common.cache.userInfo[userId];
                    this.element.innerText =  "\""+(Common.tool.isNull(user.nick)?user.userID:user.nick)+"\"" + this.info;
                }
            });
        }
        return this;
    }
}

export default MessListPointItem;
